/*           Copyright(c) 2005-2008 Dave Sexton            *
 *                   HtmlEditor Control                    *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;

namespace DaveSexton.Controls
{
	partial class HtmlToXmlConverter
	{
		private sealed class CommentReader : HtmlParserBase
		{
			#region Constructors
			/// <summary>
			/// Constructs a new instance of the <see cref="CommentReader" /> class.
			/// </summary>
			public CommentReader(TextReader reader, XmlWriter writer)
				: base(reader, writer)
			{
			}
			#endregion

			#region Methods
			public string Read()
			{
				StringBuilder comment = new StringBuilder();

				do
				{
					comment.Append(ReadTo(false, false, false, '-'));

					ReadNext();

					if (PeekNextCharacter() == '-')
					{
						ReadNext();

						if (PeekNextCharacter() == TagEnd)
						{
							ReadNext();
							break;
						}
						else
							comment.Append("--");
					}
					else
						comment.Append('-');
				}
				while (true);

				return comment.ToString();
			}
			#endregion
		}
	}
}
